package ModelLayer;
import java.util.ArrayList;
public class DVD_Register
{
    private static DVD_Register instance;
    private ArrayList<DVD> dvdCollection;
    private DVD_Register(){
        dvdCollection = new ArrayList<DVD>();
    }
    public static DVD_Register getInstance(){
        if(instance == null){
            instance = new DVD_Register();
        }
        return instance;
    }
    
    //When new DVD object is created, it is instantly passed into container
    public void addDVD(String id, String title, String artist, String publicationDate)
    {
        dvdCollection.add(new DVD( id,title,artist,publicationDate));
    }
    
    //Returns ArrayList of dvdCollection
    public ArrayList<DVD> showDVDS(){
        return dvdCollection;
    }
    
    //Finds and updates DVD according passed values
    public void updateInformation(String id, String title, String artist, String publicationDate){
        findDVD(title).update(id, artist, publicationDate);
    }
    
    //Removes DVD from the DVD collection
    public void removeDVD(String title){
        dvdCollection.remove(findDVD(title));
    }
    
    //Finds and return DVD according it's title
    public DVD findDVD(String title){
        int i = 0;
        boolean found = false;
        while(!found&&dvdCollection.size()>i){
            if(title.equals(dvdCollection.get(i).getTitle())){
                found = true; 
            }
            else{
                i++;
            }
        }
        if(!found){
            return null;
        }
        return dvdCollection.get(i);
    }
}
